<?php
session_start();

$RandomStr = md5(microtime());// md5 to generate the random string

$ResultStr = substr($RandomStr,0,8);//trim 5 digit 

$fp_two = fopen("CaptchaTxt.txt",'w');
fwrite($fp_two,$ResultStr);
fclose($fp_two);

$NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground 

$LineColor = imagecolorallocate($NewImage,0,0,0);//line color 
$TextColor = imagecolorallocate($NewImage, 0, 0, 0);//text color-white

imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image 
imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image 
imageline($NewImage,12,100,80,3,$LineColor);//create line 3 on image 

imagestring($NewImage, 5, 1, 5, $ResultStr, $TextColor);// Draw a random string horizontally 

$_SESSION['key'] = $ResultStr;// carry the data through session

//header("Content-type: image/jpeg");// out out the image 

imagejpeg($NewImage);//Output image to browser 


?>
